package com.ma.lucenedemo.controller;

import com.ma.lucenedemo.service.CarService;
import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/car")
public class IndexController {

    @Autowired
    private CarService carService;

    @RequestMapping("/test")
    public String test(){
        return "index";
    }

    /*
    * 上传excel文件到服务器
    * */
    @RequestMapping("/upload")
    @ResponseBody
    public void uploadExcel(@RequestParam("uploadFile") MultipartFile multipartFile, HttpServletResponse response) throws IOException, ParseException, InvalidFormatException {
        carService.anyParse(multipartFile,response);
    }

    /*
    * 单个检索
    * */
    @GetMapping("/singleQuery/{key}")
    @ResponseBody
    public String singleQuery(@PathVariable("key") String keyWord) throws IOException, ParseException {
        return carService.parseKey(keyWord);
    }




    /*
    * 下载执行结果
    * */

}
